<template>
    <div class="container-full">
        <div class="date-c">
            <div @click="selectTime(0)">开始日期：{{startTime?$moment(startTime).format('YYYY-MM-DD HH:mm'):"不限"}}</div>
            <div @click="selectTime(1)"
                 style="margin-top: 4px">截止日期： {{endTime?$moment(endTime).format('YYYY-MM-DD HH:mm'):"不限"}}
            </div>
            <div>
                <label class="searchBtn" @click="searchData(0)">确定</label>
                <label class="searchBtn bac-grey" @click="searchData(1)">清除</label>
            </div>
        </div>

        <div class="order-list-items">
            <div>
                <div class="title">现有库存：</div>
                <div v-if="kucunData.have.length>0">
                    <div v-for="(item,index) in kucunData.have" :key="index" class="list" @click="goList(item.id,0)">
                        <div> {{item.name}}</div>
                        <div> {{item.sumNumber}}{{item.danweiming}}</div>
                    </div>
                </div>
                <div v-else class="no-data">暂无记录</div>
            </div>
            <div>
                <div class="title">入库库存：</div>
                <div v-if="kucunData.in.length>0">
                    <div v-for="(item,index) in kucunData.in" :key="index" class="list"
                         @click="goList(item.id,0)">
                        <div> {{item.name}}</div>
                        <div> {{item.sumNumber}}{{item.danweiming}}</div>
                    </div>
                </div>

                <div v-else class="no-data">暂无记录</div>
            </div>
            <div>
                <div class="title">出库库存：</div>
                <div v-if="kucunData.out.length>0">
                    <div v-for="(item,index) in kucunData.out" :key="index" class="list" @click="goList(item.id,0)">
                        <div> {{item.name}}</div>
                        <div> {{item.sumNumber}}{{item.danweiming}}</div>
                    </div>
                </div>

                <div v-else class="no-data">暂无记录</div>
            </div>
        </div>
        <van-popup v-model="timeSection.show" position="bottom" :close-on-click-overlay="false">
            <div v-show="curTime==0">
                <van-datetime-picker v-model="curTimeValue" @cancel="timeSection.show = false"
                                     @confirm="startTimeSection" type="datetime"/>
            </div>
            <div v-show="curTime==1">
                <van-datetime-picker v-model="curTimeValue" @cancel="timeSection.show = false"
                                     @confirm="endTimeSection" type="datetime"/>
            </div>
        </van-popup>
    </div>
</template>

<script>
    import {Cell, CellGroup, Tab, Tabs, List} from 'vant';

    import NormalOrderList from '../../components/currency/order-item/normal-list-temporary-director.vue';
    import TabGroup from "../../components/currency/tab/tab.vue";
    import fly from "../../../src/libs/request.js"
    import {DatetimePicker, Popup} from 'vant';

    export default {
        name: 'salesmanIndexs',
        components: {
            [Cell.name]: Cell, [CellGroup.name]: CellGroup,
            [Tab.name]: Tab, [Tabs.name]: Tabs, [List.name]: List,
            [DatetimePicker.name]: DatetimePicker, [Popup.name]: Popup,
            NormalOrderList, TabGroup
        },
        data() {
            return {

                menDianList: [],
                menFinished: false,
                menLoading: false,
                menQuery: {
                    page: 0,
                    list_rows: 10,
                },
                timeSection: {
                    show: false,
                },
                curTime: 0,
                curTimeValue: "",
                startTime: "",
                endTime: "",
                kucunData: {}

            }
        },
        mounted() {
            this.onLoadMenDian();
        },
        methods: {
            selectTime(index) {
                this.curTime = index;
                this.timeSection.show = true
            },
            startTimeSection(data) {
                console.log('data ', data)
                this.startTime = data.getTime();
                this.timeSection.show = false
            },
            endTimeSection(data) {
                this.endTime = data.getTime();
                this.timeSection.show = false
            },
            searchData(index) {
                if (index == 1) {
                    this.startTime = "";
                    this.endTime = "";
                }

                this.onLoadMenDian()
            },
            goList(id, index) {
                this.$router.push({
                    path: `/public/yeji-detail/${id}/${index}`
                })
            },

            async onLoadMenDian() {
                let params = this.menQuery;
                params.token = this.$store.state.options.user.token;
                params.startTime = this.startTime ? parseInt(this.startTime / 1000) : "";
                params.endTime = this.endTime ? parseInt(this.endTime / 1000) : "";
                let res = await fly.post("/api/home/order/getStockReport", params);
                if (res.code == 200) {
                    this.kucunData = res.data;
                    /* let data = res.data.data || [];
                     this.menDianList = this.menDianList.concat(data);
                     this.menQuery.page++;
                     if (this.menQuery.list_rows > data.length) {
                         this.menFinished = true
                     }*/
                } else {
                    this.menFinished = true
                }
                this.menLoading = false;
            },


        }
    }
</script>

<style lang="scss" scoped>
    .date-c {
        padding: 10px;
        font-size: 14px;
        height: 80px;
        border-bottom: 3px solid #EEEEEE;
        background-color: white;
    }

    .searchBtn {
        display: inline-block;
        padding: 5px 15px;
        font-size: 12px;
        text-align: center;
        color: white;
        background-color: #00CC00;
        margin-top: 5px;
        margin-right: 10px;
    }

    .bac-grey {
        background-color: #A3A3A3 !important;
    }

    .title {
        padding: 10px 10px;
        background-color: #EEEEEE;
    }

    .list {
        padding: 10px;
        font-size: 14px;
        border-bottom: 1px solid #EEEEEE;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .page-top {
        width: 100%;
        height: 3rem;
        position: relative;

        .notice {
            position: absolute;
            top: 0rem;
            width: 100%;
            margin: 0rem;
            padding: 0.7rem 1rem;
            display: flex;
            background: rgba(255, 247, 209, 1);
            z-index: 1;
            box-sizing: border-box;

            dt {
                padding-right: 1rem;

                img {
                    width: 1.4rem;
                }
            }

            dd {
                white-space: nowrap;
                flex: 1;
                margin: 0rem;
                padding: 0rem;
                color: #ff9000;
                font-size: 1.3rem;
            }
        }
    }

    .order-list-items {
        position: relative;
        margin-bottom: 4rem;

        .el-item {
            padding: 0.5rem 1rem;
        }
    }

    .order-list-contianer {
        border-bottom: 0.4rem solid #f4f4f4;

        ul {
            display: flex;
            border-bottom: 0.1rem solid #00cc00;

            li {
                padding: 1rem 0rem;
            }
        }

        ul li {
            flex: 1;
            display: flex;
            justify-content: center;
            align-items: center;

            color: #999999;
            font-size: 1.7rem;
        }

        .active {
            background-color: #00cc00;
            color: #ffffff;
            font-weight: 540;
        }
    }
</style>
